(function (root, factory) {
  typeof define === 'function' && define.amd ? define([], factory) :
  root.iframe = factory();
}(this, function () { 'use strict';

	function createIframe(id,url,width,height,onLoadCallback,timeOut,timeOutCallback){
		let timeOutVar = setTimeout(function(){
			clearTimeout(timeOutVar);
			timeOutCallback.apply(this, arguments);
		}, timeOut);
		
		let iframe =  document.getElementById(id);
		
		if (!iframe) {
			iframe =  document.createElement("iframe");

			iframe.id=id;
			iframe.width=width;
			iframe.height=height;
			iframe.style = 'display: none';
			document.body.appendChild(iframe);

			if (iframe.attachEvent){
				iframe.attachEvent("onload", function(){
					clearTimeout(timeOutVar);
					onLoadCallback.apply(this, arguments);
				});
			} else {
				iframe.onload = function(){
					clearTimeout(timeOutVar);
					onLoadCallback.apply(this, arguments);
				};
			}

			
		}

		iframe.src=url;
		return iframe;
	}
  return {
	  createIframe: createIframe
  }

}))
